using System;
using System.Collections.Generic;
using System.Linq;

namespace DIS_WEB_Client.Repositories
{
	#region using
	using DIS_WEB_Client.Helpers;
    using DIS_Web_Client.DIS_WS_BusinessLayer;
	#endregion
	public class EmployeeRepository
	{
		public EmployeeDTO SelectByID(int id)
		{
			try
			{
                return BusService.Instance.Employee_SelectByID(id);
			}
			catch(Exception ex)
			{
				if (ex.InnerException != null)
				{
					GlobalVariables.Logger.Error(ex.InnerException.Message);
				}
				else
				{
					GlobalVariables.Logger.Error(ex.Message);
				}
			}
			return null;
		}

		public List<EmployeeDTO> RetrieveByID(int id)
		{
			try
			{
                var item = BusService.Instance.Employee_SelectByID(id);
                if (item != null)
                {
                    return new List<EmployeeDTO> { item };
                }
			}
			catch(Exception ex)
			{
				if (ex.InnerException != null)
				{
					GlobalVariables.Logger.Error(ex.InnerException.Message);
				}
				else
				{
					GlobalVariables.Logger.Error(ex.Message);
				}
			}
			return new List<EmployeeDTO>();
		}

        public EmployeeDTO SelectByUserName(string username)
        {
            try
            {
                return BusService.Instance.Employee_SelectByUserName(username);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    GlobalVariables.Logger.Error(ex.InnerException.Message);
                }
                else
                {
                    GlobalVariables.Logger.Error(ex.Message);
                }
            }
            return null;
        }

        public EmployeeDTO SelectByUserNameAndPassword(string username, string password)
        {
            try
            {
                return BusService.Instance.Employee_SelectByUserNameAndPassword(username, password);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    GlobalVariables.Logger.Error(ex.InnerException.Message);
                }
                else
                {
                    GlobalVariables.Logger.Error(ex.Message);
                }
            }
            return null;
        }
	}
}